<?php

// make sure only logged in users can see this page
gatekeeper ();
// set context to add a "cancel" option
elgg_set_context ( 'resumes_form' );

// set_page_owner(get_loggedin_user()->getGUID());
elgg_set_page_owner_guid ( $_SESSION ['user']->guid );

// set the title
$title = elgg_echo ( 'resume:add:personal' );

// start building the main column of the page
$area2 = elgg_view_title ( $title );
// Add the form to this section
if ($vars ['id']) {
	$gid = $vars ['id'];
	
	$area2 .= elgg_view_form ( "resume/savepersonal", null, array (
			'email' => 'nguyentoanuit@gmail.com' 
	) );
} else {
	$personals = elgg_get_entities ( array (
			'type' => 'object',
			'subtype' => "personal",
			'owner_guid' => elgg_get_logged_in_user_guid () 
	) );
	$name = '';
	$email = '';
	$phone = '';
	$dob = '';
	$gender = '';
	$address = '';
	$moredetail = '';
	 $count = count ( $personals );
	
		foreach ( $personals as $personal ) {
			$name = $personal->title;
			$dob = $personal->dob;
			$email = $personal->email;
			$phone = $personal->phone;
			$gender = $personal->gender;
			$address = $personal->address;
			$moredetail = $personal->description;
			
			//$personal->delete(false);
			break;
		}
	if(isset($count) && $count == 0){
		$user = elgg_get_logged_in_user_entity();
		$name = $user->name;
		$email = $user->email;
	}
	
	$area2 .= elgg_view_form ( "resume/savepersonal",null, array (
			'name' => $name,
			'email' => $email,
			'phone' => $phone,
			'dob' => $dob,
			'gender' => $gender,
			'address' => $address,
			'moredetail' => $moredetail,
	)
	 );
}
// layout the page
$body = elgg_view ( 'page/layouts/one_sidebar', array (
		'content' => $area2 
) );
// draw the page
echo elgg_view_page ( $title, $body );